class Solution{
public:
    int minSubArrayLen(int target, vector<int>&nums) {
        int left = 0, right = 0; 
        int res = nums.size() + 1; 
        int sum = 0; 
        while (right < nums.size()) {
            sum += nums[right]; 
            while (sum >= target) {
                res = min(res, right - left + 1); 
                sum -= nums[left]; 
                left++; 
            }
            right++; 
        }
        return res < nums.size() + 1 ? res : 0;
    }
};
